
var app = getApp()
Page({

  data: {
    array1: [
      'A．	商业模式与顶层战略',
      'B．	营销体系',
      'C．	企业内部管理',
      'D．	时政经济热点分析',

    ],
    question1_img: ['../../resource/check.png', '../../resource/check.png', '../../resource/check.png', '../../resource/check.png',],
    question2_img: ['../../resource/check.png', '../../resource/check.png', '../../resource/check.png', '../../resource/check.png',],
    array2: [
      'A．	完整的体系化学习方式',
      'B．	碎片化知识点学习方式',
      'C．	一对一顾问式学习方式',
      'D．	课堂授课式学习方式',

    ],
    bind3: '',
    bindname: '',
    bindtel: '',
    q1: -1,
    q2: ''
  },
  choose1: function (e) {
    var index = e.currentTarget.dataset.index
    console.log(index)
    var that = this

    for (var i = 0, len = 4; i < len; i++) {
      if (i != index) {
        this.data.question1_img[i] = '../../resource/check.png';
      } else {
        if (this.data.question1_img[i] == '../../resource/check.png') {
          this.data.question1_img[i] = '../../resource/checked.png';
        } else {
          this.data.question1_img[i] = '../../resource/check.png';
        }
      }
    }


    this.setData({
      question1_img: that.data.question1_img,
      q1: index
    })
    console.log(this.data.q1)
  },
  choose2: function (e) {
    var index = e.currentTarget.dataset.index
    console.log(index)
    var that = this
    if (this.data.question2_img[index] == '../../resource/check.png') {
      this.data.question2_img[index] = '../../resource/checked.png';

    } else {

      this.data.question2_img[index] = '../../resource/check.png';
    }
    this.setData({

      question2_img: that.data.question2_img,
    })
    console.log(this.data.question2_img[index])
  },

  bind3: function (e) {
    this.setData({
      bind3: e.detail.value
    })
  },

  bindname: function (e) {
    this.setData({
      bindname: e.detail.value
    })
  },

  bindtel: function (e) {
    this.setData({
      bindtel: e.detail.value
    })
  },
  submit: function () {
    console.log(this.data.q1)

    var qq='';
    for (var i = 0, len = 4; i < len; i++) {
      if (this.data.question2_img[i] == '../../resource/checked.png') {
        qq = qq + i + ",";
      }
    }
    if (this.data.q1 == -1 || qq == '' || this.data.bind3 == '' || this.data.bindname == '' || this.data.bindtel==''){
      wx.showToast({
        title: '请填写完整信息',
        image:'../../resource/warn-pay.png'
      })
    }
    else{
      wx.showLoading({
        title: '提交中...',
      })
      var that = this
      wx.request({
        url: 'https://xiaochengxu.fincoder.com/index.php/Home/Diaocha/Diaocha2',
        data: {
          one: that.data.q1,
          two: qq,
          three: that.data.bind3,
          name: that.data.bindname,
          mobile: that.data.bindtel,

        },
        header: {
          'content-type': 'application/json'
        },
        success: function (res) {
          wx.hideLoading()
          if (res.data.status === 1) {
            // wx.showLoading({
            //   title: '提交成功',
            // })
            wx.navigateTo({ url: '../puke/puke'})

            //  wx.navigateBack({
               
            //  })
         
          } else {

          }
        }, fail: function () {
          wx.hideLoading()
        },
        complete: function () {
          wx.hideLoading()
        }
      })
     }

  }
})